package com.hxm.webview.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hxm.webview.R;
import com.hxm.webview.httprequstpackage.WeChatData;

import java.util.List;

/**
 * Created by HXM on 2016/8/12.
 * Description:
 */
public class WeChatListActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<WeChatData.ListBean> mData;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wechatlist);
        initView();
    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(new MyAdapter(mData));
//        recyclerView.addItemDecoration();
    }

    class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
        private LayoutInflater inflater;
        private List<WeChatData.ListBean> listData;

        public MyAdapter(List<WeChatData.ListBean> listData) {
            this.listData = listData;
            inflater=LayoutInflater.from(WeChatListActivity.this);
        }

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            MyViewHolder holder=new MyViewHolder(inflater.inflate(R.layout.wechatlist_item,parent,false));
            return holder;
        }

        @Override
        public void onBindViewHolder(MyViewHolder holder, int position) {
            holder.tvTitle.setText(listData.get(position).getTitle());
            holder.tvArticleSource.setText(listData.get(position).getSource());
        }

        @Override
        public int getItemCount() {
            return listData.size();
        }

        class MyViewHolder extends RecyclerView.ViewHolder {
            TextView tvTitle,tvArticleSource;
            public MyViewHolder(View itemView) {
                super(itemView);
                tvTitle= (TextView) itemView.findViewById(R.id.wechat_title);
                tvArticleSource= (TextView) itemView.findViewById(R.id.article_source);
            }
        }
    }
}
